package main

import (
	"encoding/json"
	"github.com/golang/protobuf/proto"
	"fmt"
	goproto "goTestToMod/grpc/proto"
)

type Hello struct {
	Nmae string `json:"name"`
	Age int `json:"age"`
	Courses []string `json:"course"`
}

func main() {
	//req := Hello{"ice", 18, []string{"minishop"}}
	req := goproto.HelloRequse{
		Name: "boby",
		Age: 18,
		Courses: []string{"OK", "123", "6454"},
	}
	goProto, _ := proto.Marshal(&req)
	fmt.Printf("protobuf bite： %b , len byte: %d , len string: %d \n", goProto, len(goProto), len(goProto))

	// json
	jsonstruct := Hello{
		"ttt", 18, []string{"123"},
	}
	helloJson, _ := json.Marshal(&jsonstruct)
	fmt.Printf("json bite： %b, len byte: %d , len string: %d\n", helloJson, len(helloJson), len(string(helloJson)))

	// 解析proto
	decodeProto := goproto.HelloRequse{}
	proto.Unmarshal(goProto, &decodeProto)
	fmt.Printf("decode protobuf struct %v \n", decodeProto)
}